<?php

namespace Biz\model\brand;

class BrandHhzCard extends \Doraemon\pockets\datebase\BaseDbModel
{
    const _CONFIG_FILE_ = 'db_store';

    const _CONFIG_SELECT_ = 'db_store';

    const _DATABASE_ = 'store';

    const _TABLE_NAME = 'brand_hhz_card';

    const TEMPLATE_ONE = 1;//模版1（品牌名片-竖版1）
    const TEMPLATE_TWO = 2;//模版2（品牌名片-竖版2）
    const TEMPLATE_THREE = 3;//模版3（品牌名片-横版）
    const TEMPLATE_RANK_HONORS_YEAR = 4;//榜单荣誉-年度
    const TEMPLATE_RANK_HONORS_QUARTER = 5;//榜单荣誉-季度

    const TEMPLATE_DESC = [
        self::TEMPLATE_ONE => '品牌名片-竖版1',
        self::TEMPLATE_TWO => '品牌名片-竖版2',
        self::TEMPLATE_THREE => '品牌名片-横版',
        self::TEMPLATE_RANK_HONORS_YEAR => '品牌榜单荣誉-年度',
        self::TEMPLATE_RANK_HONORS_QUARTER => '品牌榜单荣誉-季度',
    ];

    const TEMPLATE_CARD_SIZE = [
        self::TEMPLATE_ONE => [
            1 => ['width' => 1463, 'height' => 2079],
            2 => ['width' => 1126, 'height' => 1600],
            3 => ['width' => 1039, 'height' => 1476]
        ],
        self::TEMPLATE_TWO => [
            1 => ['width' => 1463, 'height' => 2079],
            2 => ['width' => 1126, 'height' => 1600],
            3 => ['width' => 1039, 'height' => 1476],
        ],
        self::TEMPLATE_THREE => [
            1 => ['width' => 2078, 'height' => 1463],
            2 => ['width' => 1476, 'height' => 1039],
            3 => ['width' => 1126, 'height' => 793]
        ],
        self::TEMPLATE_RANK_HONORS_YEAR => [
            1 => ['width' => 1463, 'height' => 2079],
            2 => ['width' => 1126, 'height' => 1600],
            3 => ['width' => 1039, 'height' => 1476],
        ],
        self::TEMPLATE_RANK_HONORS_QUARTER => [
            1 => ['width' => 1463, 'height' => 2079],
            2 => ['width' => 1126, 'height' => 1600],
            3 => ['width' => 1039, 'height' => 1476],
        ],

    ];

    public static function getInfo($where, $select = '*')
    {
        return self::get($select, $where);
    }

    public static function selectList($where, $select = '*')
    {
        $list = self::select($select, $where);
        return $list;
    }

    public static function selectCount($where)
    {
        $count = self::count('id', $where);
        return $count;
    }

    public static function insertData($data)
    {
        if (!isset($data['addtime'])) {
            $data['addtime'] = date('Y-m-d H:i:s');
        }
        if (!isset($data['edittime'])) {
            $data['edittime'] = date('Y-m-d H:i:s');
        }
        $ret = self::insert($data);
        if ($ret->errorCode() !== '00000') {
            return false;
        }
        return self::id();
    }

    public static function updateData($data, $where)
    {
        if (!isset($data['edittime'])) {
            $data['edittime'] = date('Y-m-d H:i:s');
        }
        $ret = self::update($data, $where);
        if ($ret->errorCode() !== '00000') {
            return false;
        }
        return true;
    }
}